Skip to content

Ignore unknown kty in KeySet.import_key_set (RFC 7517 §5) - #103

Merged
lepture merged 2 commits into
authlib:mainfrom
RalphBragg:fix/jwks-import-ignore-unknown-kty
Jul 25, 2026
Merged

Ignore unknown kty in KeySet.import_key_set (RFC 7517 §5)#103
lepture merged 2 commits into
authlib:mainfrom
RalphBragg:fix/jwks-import-ignore-unknown-kty

Conversation

@RalphBragg

Copy link
Copy Markdown
Contributor

What

KeySet.import_key_set now skips a key whose kty is present but not in the registry, instead of raising InvalidKeyTypeError and failing the whole set.

Why

Today import_key_set imports each key eagerly, so the first key with an unrecognised kty raises (Invalid key type: '...') and the entire set fails. RFC 7517 §5 says a processor SHOULD ignore key types it does not understand.

This is becoming a live issue as post-quantum keys (ML-DSA, kty:"AKP", RFC 9964) begin appearing in published JWKS next to RSA/EC keys: one unknown key otherwise stops the classical keys next to it from verifying. (Companion to the same fix in authlib, authlib/authlib#914, since authlib.jose points here as its successor.)

Change

  • import_key_set skips only keys whose kty is explicitly present and not in registry_cls.key_types; a recognised-but-malformed key still raises, and a set with no usable keys still raises MissingKeyError as before.
  • Added test_import_key_set_ignores_unknown_kty.

tests/jwk/test_jwk_set.py passes (11 passed).

import_key_set raised InvalidKeyTypeError on the first key whose kty was not
in the registry, failing the whole set. Skip a key whose kty is present but
unrecognised, per RFC 7517 Section 5, so classical keys published alongside a
post-quantum key (ML-DSA, kty AKP) remain usable.
@RalphBragg

Copy link
Copy Markdown
Contributor Author

Tracking issue: #104. This PR fixes it.

@lepture

lepture commented Jul 24, 2026

Copy link
Copy Markdown
Member

I think you can just use try-catch InvalidKeyTypeError, instead of detect it yourself.

Switch from a pre-check of the kty registry to catching InvalidKeyTypeError
per key, as suggested by @lepture. Same behaviour: an unrecognised key type
is skipped (RFC 7517 Section 5) while the rest of the set loads.
@RalphBragg

Copy link
Copy Markdown
Contributor Author

Done, updated to try/except InvalidKeyTypeError as you suggested rather than pre-checking the registry. Same behaviour: an unrecognised kty is skipped (RFC 7517 §5) and the rest of the set loads, and test_import_key_set_ignores_unknown_kty still passes. Thanks for the review.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7facdee) to head (ea19ea6).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #103   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           47        47           
  Lines         2932      2935    +3     
  Branches       347       347           
=========================================
+ Hits          2932      2935    +3     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lepture
lepture merged commit 4dcd363 into authlib:main Jul 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonWebKey.import_key_set raises KeyError on an unknown kty, failing the whole JWK Set (RFC 7517 §5)

2 participants